/**
 * 初始化地址
 */
function initAddress(pBox,pName,pId,cBox,cName,cId,aBox,aName,aId,addressfirm){
	if(addressfirm.ClearType >= 1){
		//document.getElementById(pName).value = i18n.order_province;
		document.getElementById(pId).value = '';
		//document.getElementById(cName).value = i18n.order_city;
		document.getElementById(cId).value = '';
		//document.getElementById(aName).value = i18n.order_district;
		document.getElementById(aId).value = '';

		AddressCity.removeBox(cBox);
		AddressArea.removeBox(aBox);
		
		if("HK"==addressfirm.AreaScope || "MC"==addressfirm.AreaScope){
			$("#"+pName).attr('value',i18n.order_city).attr('tip',i18n.order_city);
			$("#"+cName).attr('value',i18n.order_di2strict).attr('tip',i18n.order_di2strict);
			$("#"+aName).attr('value',i18n.order_area).attr('tip',i18n.order_area);
		}else if("TW"==addressfirm.AreaScope){
			$("#"+pName).attr('value',i18n.order_taiwan).attr('tip',i18n.order_taiwan);
			$("#"+cName).attr('value',i18n.order_di2strict).attr('tip',i18n.order_di2strict);
			$("#"+aName).attr('value',i18n.order_area).attr('tip',i18n.order_area);
		}else{
			
			$("#"+pName).attr('value',i18n.order_province).attr('tip',i18n.order_province);
			$("#"+cName).attr('value',i18n.order_city).attr('tip',i18n.order_city);
			$("#"+aName).attr('value',i18n.order_district).attr('tip',i18n.order_district);
		}
	}
	var countyCode = addressfirm.AreaScope==''? getRegionCode():addressfirm.AreaScope;
	var langCode = addressfirm.LangCode==''? i18n.lang:addressfirm.LangCode;
	var areaData = {input:aName, idTT:aId, boxId:aBox,changeAreaFunc:addressfirm.ChangeAreaFuncName};
	var cityData = {input:cName, idTT:cId, boxId:cBox, isLowerLevel:'yes', lowerData:areaData,changeFunc:addressfirm.ChangeFuncName};
	var provinceData = {input:pName, idTT:pId, boxId:pBox, isLowerLevel:'yes', lowerData:cityData,countyCode:countyCode,langCode:langCode,changeFunc:addressfirm.provinceChangeFunc};

	AddressProvince.getAddressData(provinceData);

	
	if(addressfirm.ClearType == 2){
		AddressCity.getAddressData(cityData);
		AddressArea.getAddressData(areaData);
	}
}


/**地址控件帮助类**/
var AddressHelper = {};

/**
 * 判断是否为空
 */
AddressHelper.isEmpty = function(obj){
	if(typeof obj != undefined && obj != '' && obj != null){
		return false;
	}
	return true;
};

AddressHelper.PROVINCE_NULL_NAME = i18n.order_province;
AddressHelper.CITY_NULL_NAME = i18n.order_city;
AddressHelper.AREA_NULL_NAME = i18n.order_district;

/**
 * AddressHelper：加载城市和地区
 */
AddressHelper.loadCityAndAreaData = function(provinceId,provinceName,cityId,cityName,cityBox,areaId,areaName,areaBox,addressfirm){
	var provinceIdVal = $("#"+provinceId).val();
	var provinceNameVal = $("#"+provinceName).val();
	var cityIdVal =  $("#"+cityId).val();
	var cityNameVal =  $("#"+cityName).val();
	var countyCode =getRegionCode();
	var langCode =i18n.lang;
	var changeFunc='';
	var changeAreaFunc='';
	if(addressfirm){
		countyCode = addressfirm.AreaScope==''? countyCode:addressfirm.AreaScope;
		langCode = addressfirm.langCode==''? langCode:addressfirm.LangCode;
		changeAreaFunc = addressfirm.ChangeAreaFuncName;
		changeFunc = addressfirm.ChangeFuncName;
	}
	if(provinceIdVal != '' && provinceNameVal != '' && provinceNameVal != AddressHelper.PROVINCE_NULL_NAME){
		var cityData;
		if(cityIdVal != '' && cityNameVal != '' && cityNameVal != AddressHelper.CITY_NULL_NAME){
			var areaData = {parentInput:AddressProvince._m.$('#'+ cityName),input:areaName, idTT:areaId, parentId:cityIdVal+'/'+cityNameVal, boxId:areaBox,countyCode:countyCode,langCode:langCode,changeAreaFunc:changeAreaFunc};
			cityData = {parentInput:AddressProvince._m.$('#'+ provinceName),input:cityName, idTT:cityId, parentId:provinceIdVal+'/'+provinceNameVal, boxId:cityBox,isLowerLevel:'yes',lowerData:areaData,countyCode:countyCode,langCode:langCode,changeFunc:changeFunc};
		}else{
			var areaData = {parentInput:AddressProvince._m.$('#'+ cityName),input:areaName, idTT:areaId, parentId:'', boxId:areaBox,countyCode:countyCode,langCode:langCode,changeAreaFunc:changeAreaFunc};
			cityData = {parentInput:AddressProvince._m.$('#'+ provinceName),input:cityName, idTT:cityId, parentId:provinceIdVal+'/'+provinceNameVal, boxId:cityBox,isLowerLevel:'yes',lowerData:areaData,countyCode:countyCode,langCode:langCode,changeFunc:changeFunc};
		}
		AddressCity.getAddressData(cityData);
	}else{
		AddressCity.removeBox(cityBox);
		AddressArea.removeBox(areaBox);
	}
};

